package com.jbit.jboa.dao.impl;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.List;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.jbit.jboa.entity.Checkresult;

/**
 * A data access object (DAO) providing persistence and search support for
 * Checkresult entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.jbit.jboa.entity.Checkresult
 * @author MyEclipse Persistence Tools
 */

public class CheckresultDAO extends HibernateDaoSupport {
	private static final Logger log = LoggerFactory
			.getLogger(CheckresultDAO.class);
	// property constants
	public static final String SHEET_TYPE = "sheetType";
	public static final String TYPE = "type";
	public static final String CHECKER_SN = "checkerSn";
	public static final String RESULT = "result";
	public static final String COMM = "comm";

	protected void initDao() {
		// do nothing
	}

	public void save(Checkresult transientInstance) {
		log.debug("saving Checkresult instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Checkresult persistentInstance) {
		log.debug("deleting Checkresult instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Checkresult findById(java.math.BigDecimal id) {
		log.debug("getting Checkresult instance with id: " + id);
		try {
			Checkresult instance = (Checkresult) getHibernateTemplate().get(
					"com.jbit.jboa.hibernate.Checkresult", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Checkresult instance) {
		log.debug("finding Checkresult instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Checkresult instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Checkresult as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findBySheetType(Object sheetType) {
		return findByProperty(SHEET_TYPE, sheetType);
	}

	public List findByType(Object type) {
		return findByProperty(TYPE, type);
	}

	public List findByCheckerSn(Object checkerSn) {
		return findByProperty(CHECKER_SN, checkerSn);
	}

	public List findByResult(Object result) {
		return findByProperty(RESULT, result);
	}

	public List findByComm(Object comm) {
		return findByProperty(COMM, comm);
	}

	public List findAll() {
		log.debug("finding all Checkresult instances");
		try {
			String queryString = "from Checkresult";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Checkresult merge(Checkresult detachedInstance) {
		log.debug("merging Checkresult instance");
		try {
			Checkresult result = (Checkresult) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Checkresult instance) {
		log.debug("attaching dirty Checkresult instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Checkresult instance) {
		log.debug("attaching clean Checkresult instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static CheckresultDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (CheckresultDAO) ctx.getBean("CheckresultDAO");
	}
}